﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Billing.Win
{
    public partial class AccountsSelectionForm : Billing.WindowsBase.BaseList
    {
        [Browsable(false)]
        public bool FilterByClientTypeID
        {
            get { return ucClientBillingPhones1.FilterByClientTypeID; }
            set { ucClientBillingPhones1.FilterByClientTypeID = value; }
        }

        public override void PrepareForSelectDialogStyle()
        {
            base.PrepareForSelectDialogStyle();
            this.PanelTopVisible = true;
        }

        public AccountsSelectionForm()
            : this(true)
        {

        }

        public AccountsSelectionForm(bool Register)
            : base(Register)
        {
            InitializeComponent();
            clientsList.CurrentChanged += new EventHandler(clientsList_CurrentChanged);
            clientsList.ChangePage += new EventHandler(clientsList_ChangePage);
            ClientsSearch.SearchDone += new EventHandler(clientsSearch_SearchDone);
            ucClientBillingPhones1.CurrentChanged += new EventHandler(ucClientBillingPhones1_CurrentChanged);
            ucClientBillingPhones1.DoubleClick += new EventHandler(ucClientBillingPhones1_DoubleClick);
        }

        void ucClientBillingPhones1_DoubleClick(object sender, EventArgs e)
        {
            this.onSelect();
        }

        public AccountsSelectionForm(bool register, bool filterByClientTypeID)
            : this(register)
        {
            this.FilterByClientTypeID = filterByClientTypeID;
        }

        void ucClientBillingPhones1_CurrentChanged(object sender, EventArgs e)
        {
            bsElement.Clear();
            if (ucClientBillingPhones1.Account != null)
                bsElement.Add(ucClientBillingPhones1.Account);
        }

        void clientsSearch_SearchDone(object sender, EventArgs e)
        {
            clientsList.SearchStatistics = ClientsSearch.SearchStatistics;
            clientsList.DataSource = ClientsSearch.Results;
        }

        void clientsList_ChangePage(object sender, EventArgs e)
        {
            ClientsSearch.CurrentPageNumber = clientsList.PageNumber;
            ClientsSearch.Search();
        }

        void clientsList_CurrentChanged(object sender, EventArgs e)
        {
            ucClientBillingPhones1.Initialize(clientsList.DataObject, ClientsSearch.PhoneNumber);
        }
    }
}
